﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Platform.Dc
{
    /// <summary>
    /// 供应商字典
    /// </summary>
    public class SplerDictService : CrudAppService<SplerDict, SplerDictDto, Guid, SplerDictInput, SplerDictCreateDto, SplerDictUpdateDto>
    {
        private IRepository<SplerDict, Guid> _splerDictRepository;

        public SplerDictService(IRepository<SplerDict, Guid> splerDictRepository) : base(splerDictRepository)
        {
            _splerDictRepository = splerDictRepository;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<SplerDictDto>> GetListAsync(SplerDictInput input)
        {
            var iQuery = await _splerDictRepository.GetQueryableAsync();

            if (input.SkipCount == 0)
            {
                var itemsDto = ObjectMapper.Map<List<SplerDict>, List<SplerDictDto>>(iQuery.ToList());

                return new PagedResultDto<SplerDictDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.SkipCount, input.MaxResultCount);
                var itemsDto = ObjectMapper.Map<List<SplerDict>, List<SplerDictDto>>(items.ToList());

                return new PagedResultDto<SplerDictDto>(totalCount, itemsDto);
            }
        }
    }
}